(function(app){
	app
		.controller("content_28_inputCtrl",["$scope","$state","myFactory","$http","$stateParams","$state","$q","$ionicHistory",function($scope,$state,myFactory,$http,$stateParams,$state,$q,$ionicHistory){
			//接收参数
			var itemId = $stateParams.changeTypeId;//变更项目ID
			var chdrnum01 =  $stateParams.chdrnum01; //保单号
			var chdrcoy = $stateParams.chdrcoy; //保单公司号码
			var searchParam = $stateParams.searchParam;
			var policyData;//保单详情
			var itemData;//用于接收初始化查询initContentItem的内容，里面存在各种各样的内容，比如item038
			var initFlag = false;//检测标志，在初始化函数完成后，会被置为true
			var token=sessionStorage.getItem("token");
			//参数绑定
			$scope.chdrnum01 =  $stateParams.chdrnum01;

			/*S2022033121820集团文件对标《动产及权利担保常见法律实务要点指导手册》-保全系统更新保单借款、还款阅读文件需求 add by huanghk 20220613 start*/
			$scope.readFlag = false;//阅读协议标志，默认为false
			$scope.loanAgreementShow = false;
			/*S2022033121820集团文件对标《动产及权利担保常见法律实务要点指导手册》-保全系统更新保单借款、还款阅读文件需求 add by huanghk 20220613 end*/
			
		    //S2023062626494营运APP养老欺骗风险防范&产品转换风险提示系统需求 add by huanghk 20230803 start
	        $scope.butShow = true;
	        //S2023062626494营运APP养老欺骗风险防范&产品转换风险提示系统需求 add by huanghk 20230803 end
			
/**********************************************************初始化部分begin****************************************************/
			//初始化查询变更项内容
			$scope.load = function () {
				myFactory.loadingShow();//显示加载圈
				var timestamp=myFactory.getTimetamp();
				var sfis= "itemId-token-timestamp";
				var signStr="itemId="+itemId+"&token="+token+"&timestamp="+timestamp;//encodeURI(name)
				var sign = myFactory.hex(signStr);
				$http({
					method: 'GET',
					url: app.domain + 'input/initContentItem.action',
					params: {'itemId': itemId,'sign':sign,'sfis':sfis,'token':token,'timestamp':timestamp}
				}).then(function successCallback(response) {
					if (response.data.success) {
						itemData = response.data.data.modelMap;
						$scope.item28 = itemData.item28;
						
						//现金价值
						/*var surrvalInt = parseFloat($scope.item28.itemCalculate.surrval) + parseFloat($scope.item28.itemCalculate.surrval);
						$('#surrvalInt').html(surrvalInt);*/
						
						//已借款本息金额
						var plAmtInt = parseFloat($scope.item28.itemCalculate.plamt) + parseFloat($scope.item28.itemCalculate.plint);
						$('#plAmtInt').html(plAmtInt);
	
						//已垫缴本息金额
						var aplAmtInt = parseFloat($scope.item28.itemCalculate.aplamt)+parseFloat($scope.item28.itemCalculate.aplint);
						$('#aplAmtInt').html(aplAmtInt);
	
						//最高可借款金额
						var maxAmtInt = plAmtInt+aplAmtInt+parseFloat($scope.item28.itemCalculate.loanallow);
					    $('#maxAmtInt').html(maxAmtInt.toFixed(2));
					    
					    /*S2022033121820集团文件对标《动产及权利担保常见法律实务要点指导手册》-保全系统更新保单借款、还款阅读文件需求 add by huanghk 20220613 start*/
					    $scope.LOANRAT = itemData.LOANRAT;//借款利率
					    $scope.JKXY = itemData.JKXY;//借款协议版本
					    if($scope.JKXY==""){
					    	$scope.loanAgreementShow = false;
					    }else{
					    	$scope.loanAgreementShow = true;
					    }
					    /*S2022033121820集团文件对标《动产及权利担保常见法律实务要点指导手册》-保全系统更新保单借款、还款阅读文件需求 add by huanghk 20220613 end*/
					    
					    //S2023062626494APP养老欺骗风险防范&产品转换风险提示系统需求 add by huanghk 20230809 start
					    $scope.owAge = itemData.owAge;//投保人年龄
					    //S2023062626494APP养老欺骗风险防范&产品转换风险提示系统需求 add by huanghk 20230809 end
					    
					    initFlag=true;//标识初始化成功
					}
					myFactory.loadingHide();
				}, function errorCallback(response) {
					myFactory.loadingHide();
					myFactory.alert("","初始化查询变更项内容失败!","info");
				});
			}
			
			

/**********************************************************初始化部分end******************************************************/			
			
			//重新受理
			$scope.renew = function(){
				myFactory.renew();
			}
			//退出移动保全
			$scope.exit = function(){
				myFactory.exit();
			}
			//返回函数
			$scope.goBack = function () {
				myFactory.goBack();
			}
			
			//保单详情弹框
			$scope.showPolicyDetail = function(){
				modal('open','policyModalOn28Input','overwindowOn28Input','policyCloseXOn28Input');
				var timestamp=myFactory.getTimetamp();
				var sfis= "chdrnum-chdrcoy-token-timestamp";
				var signStr="chdrnum="+chdrnum01+"&chdrcoy="+chdrcoy+"&token="+token+"&timestamp="+timestamp;//encodeURI(name)
				var sign = myFactory.hex(signStr);
				//初始化时候查询保单详情
				$http({
					method: 'GET',
					url: app.domain + 'query/restFindPolicyDetail.action',
					params: {'chdrnum': chdrnum01,'chdrcoy': chdrcoy,'sign':sign,'sfis':sfis,'token':token,'timestamp':timestamp}
				}).then(function successCallback(response) {
					if (response.data.success) {
						policyData = response.data.data;
						$scope.policyData = policyData;//绑定至页面
						$scope.policyData.ptdate01=myFactory.DateTools($scope.policyData.ptdate01);
					}
				}, function errorCallback(response) {
					myFactory.alert("","初始化查询订单详情失败!","info");
				});
			}
			//保单详情弹窗关闭函数
			$scope.policyCancelOn28Input = function(){
				modal('close','policyModalOn28Input','overwindowOn28Input','policyCloseXOn28Input');
			}
			//关闭遮罩
			$scope.overwindowClose = function(){
				//$(".overwindow").show();
				$(".overwindow").hide();
				$(".overmodal").hide();
			}
			//借款详情
			$scope.detail = function(){
				$("#myDialog").fadeToggle(50);

				$("#myDialog .myDialog_content .btn_close").click(function(){
					$(this).parents('#myDialog').fadeOut(50);
				});
				
				$("#myDialog .myDialog_black").click(function(){
					$(this).parent('#myDialog').fadeOut(50);
				});
			}
			
			/*S2022013021184监管类-银行令〔2022〕1号营运相关系统功能需求 add by huanghaokun 20220315 start*/
			$scope.changeReason = function(){
				var options = "";
				options =$("#reasonSelect option:selected");
				$scope.reasonInput = options.text();
			}
			/*S2022013021184监管类-银行令〔2022〕1号营运相关系统功能需求 add by huanghaokun 20220315 end*/
			
			//下一步
			$scope.nextStep = function(){
				//判断是否初始化完成了，如果失败，不予进入下一步
				if(!initFlag){
					myFactory.alert("","初始化时失败，请返回上一步重试","info");
					return;
				}
				
				/*S2022033121820集团文件对标《动产及权利担保常见法律实务要点指导手册》-保全系统更新保单借款、还款阅读文件需求 add by huanghk 20220613 start*/
				var readImageFlag = $("#readImageFlag").val();
				//S2023062626494营运APP养老欺骗风险防范&产品转换风险提示系统需求 add by huanghk 20230803 start
	    		if(readImageFlag=="false"){
	    			if($scope.loanAgreementShow){
	    				myFactory.alert('',"请阅读《保险单借款风险提示》、《保险单借款协议》、《客户信息使用授权声明》和《中信保诚隐私政策》！",'info');
	    			}else{
	    				myFactory.alert('',"请阅读《保险单借款风险提示》、《客户信息使用授权声明》和《中信保诚隐私政策》！",'info');
	    			}
	    			return;
	    		}
	    		//S2023062626494营运APP养老欺骗风险防范&产品转换风险提示系统需求 add by huanghk 20230803 end
	    		/*S2022033121820集团文件对标《动产及权利担保常见法律实务要点指导手册》-保全系统更新保单借款、还款阅读文件需求 add by huanghk 20220613 end*/
				
				var LoanAMT = $("#LoanAMT").val();
				var benAmtInt = $("#benAmtInt").html();
				
			    if(parseFloat(LoanAMT)== 0 || LoanAMT==""){
			    	myFactory.alert("","请填写借款金额!","info");
					return false;
			    }else{
			        var reg = /^\d{0,8}\.{0,1}(\d{1,2})?$/;
			        if(!reg.test(LoanAMT)){
			        	myFactory.alert("","请填写正确借款金额!","info");
			        	return false;
			        }
			    }
			    
			    if(benAmtInt == "" || benAmtInt == null || benAmtInt == undefined){
			    	myFactory.alert("","系统加载异常，请返回重试","info");
					return false;
			    }
			    

			    benAmtInt = parseFloat(benAmtInt);
			    LoanAMT = parseFloat(LoanAMT);
			   
			    if(LoanAMT>benAmtInt){
			    	myFactory.alert("","借款金额大于本次最高可借款金额，需重新输入!","info");
					return false;
			    }
			    
                /*S2022013021184监管类-银行令〔2022〕1号营运相关系统功能需求 add by huanghaokun 20220315 start*/
			    var reasonInput = $("#reasonInput").val();
			    var reason = $("#reasonSelect option:selected").val(); //借款原因
			    if(reason==null || reason == ""){
			    	myFactory.alert("","请选择借款原因!","info");
					return false;
			    }
			    /*S2022013021184监管类-银行令〔2022〕1号营运相关系统功能需求 add by huanghaokun 20220315 end*/
			    
			    //S2023062626494APP养老欺骗风险防范&产品转换风险提示系统需求 add by huanghk 20230809 start
			    if($scope.owAge>=60){
					$scope.riskWarningOpen("2");
					return false;
				}
			    //S2023062626494APP养老欺骗风险防范&产品转换风险提示系统需求 add by huanghk 20230809 end
			    
				var item = {
					"loanAMT":LoanAMT,
					/*S2022013021184监管类-银行令〔2022〕1号营运相关系统功能需求 update by huanghaokun 20220315 start*/
					"itemId":itemId,
					"reason":reason,
					"reasonNme":reasonInput
					/*S2022013021184监管类-银行令〔2022〕1号营运相关系统功能需求 update by huanghaokun 20220315 end*/
				}
				
				$ionicHistory.clearCache().then(function(){ 
					$state.go('content_check_main',{
						itemId:itemId,
						item:item,
						chdrnum01:chdrnum01,
						chdrcoy:chdrcoy,
						searchParam:searchParam
					});
				})
			}
			
			//S2023062626494APP养老欺骗风险防范&产品转换风险提示系统需求 add by huanghk 20230809 start
			$scope.tonext = function(){
				$scope.riskWarningClose();
				var LoanAMT = $("#LoanAMT").val();
				LoanAMT = parseFloat(LoanAMT);
				var reason = $("#reasonSelect option:selected").val(); //借款原因
				var reasonInput = $("#reasonInput").val();
				var item = {
					"loanAMT":LoanAMT,
					"itemId":itemId,
					"reason":reason,
					"reasonNme":reasonInput
				}
				$ionicHistory.clearCache().then(function(){ 
					$state.go('content_check_main',{
						itemId:itemId,
						item:item,
						chdrnum01:chdrnum01,
						chdrcoy:chdrcoy,
						searchParam:searchParam
					});
				})
			}
			//S2023062626494APP养老欺骗风险防范&产品转换风险提示系统需求 add by huanghk 20230809 end
			
			/*S2022033121820集团文件对标《动产及权利担保常见法律实务要点指导手册》-保全系统更新保单借款、还款阅读文件需求 add by huanghk 20220613 start*/
			$scope.changeReadFlag = function(){
				$scope.readFlag = !$scope.readFlag;
			}
			//保险单借款协议
	        $scope.agreementOpen = function() {
	        	if($scope.JKXY=="HYRS"){
	        		modal('open', 'hyrs_model', 'overwindowOn28Input');
	        	}else if($scope.JKXY=="FTLWN"){
	        		modal('open', 'ftlwn_model', 'overwindowOn28Input');
	        	}
	        }
	        $scope.agreementClose = function() {
	        	if($scope.JKXY=="HYRS"){
	        		modal('close', 'hyrs_model', 'overwindowOn28Input');
	        	}else if($scope.JKXY=="FTLWN"){
	        		modal('close', 'ftlwn_model', 'overwindowOn28Input');
	        	}
	        }
	    	
	        //客户信息使用授权声明
	        $scope.sysmOpen = function() {
	        	modal('open', 'sysm_model', 'overwindowOn28Input');
	        }
	        $scope.sysmClose = function() {
	        	modal('close', 'sysm_model', 'overwindowOn28Input');
	        }
	    	/*S2022033121820集团文件对标《动产及权利担保常见法律实务要点指导手册》-保全系统更新保单借款、还款阅读文件需求 add by huanghk 20220613 end*/
	        //S2022102124053营运系统增加隐私政策需求 add by huanghk 20230213 start
	        $scope.privacyOpen = function(){
				$state.go('privacy', {
                    itemId: itemId,
                    chdrnum01: chdrnum01,
                    chdrcoy: chdrcoy
                });
			}
	      //S2022102124053营运系统增加隐私政策需求 add by huanghk 20230213 end
	      
	      //S2023062626494营运APP养老欺骗风险防范&产品转换风险提示系统需求 add by huanghk 20230803 start
	      //保险单借款风险提示
	        $scope.riskWarningOpen = function(type) {
				if(type=='1'){
					$scope.butShow = true;
				}else{
					$scope.butShow = false;
				}
				modal('open', 'riskWarning_model', 'overwindowOn28Input');
	        }
	        $scope.riskWarningClose = function() {
				modal('close', 'riskWarning_model', 'overwindowOn28Input');
	        }
	      //S2023062626494营运APP养老欺骗风险防范&产品转换风险提示系统需求 add by huanghk 20230803 end
		}]);    
		//指针弹窗
		app.directive('infoid',function(){
			return {
				restrict: 'EA',		//指明指令在DOM里面以什么形式被声明,EA.表示即可以是元素也可以是属性
				templateUrl: 'html/input/content_base_info.html'+app.clearCache,
				replace: true,		//设置解析后，DOM声明的指令是否消失
				link: function(scope,element,attrs){  //链接函数负责注册DOM事件和更新DOM,
					console.log('指令完成');
				}
			}
		});
})(app)